<?php
/**
 * Created by PhpStorm.
 * User: yangfan
 * Date: 2019/11/19
 * Time: 9:05 AM
 */

namespace App\BO\Coupon\CouponProductSkuCheck;

use Illuminate\Support\Facades\Log;

class ExpiredCheck implements ICouponProductSkuCheck
{
    /**
     * @param CouponProductSkuCheckMeta $checkMeta
     * @param \Closure $next
     * @return bool|mixed
     */
    public static function check(CouponProductSkuCheckMeta $checkMeta, \Closure $next)
    {
        $coupon = $checkMeta->getCouponEntity();
        if ($coupon->expired()) {
            //  优惠券已经过期
            Log::info('优惠券' . $coupon->getId() . '已经过期');
            $checkResultWrapper = new CheckResultWrapper($checkMeta->getCouponEntity());
            $checkResultWrapper->setMessage('优惠券已经过期');
            return $checkResultWrapper;
        }

        return $next($checkMeta);
    }
}
